package org.yucc.util;

import java.util.List;

import org.yucc.db.data.LoginUser;
import org.yucc.ui.R;
import org.yucc.ui.UserInfo;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class LoginUserAdapter extends BaseAdapter {

	private List<LoginUser> users = null;
	private Activity con = null;

	public LoginUserAdapter(Activity con, List<LoginUser> users) {
		super();
		this.users = users;
		this.con = con;
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		// Inflate the views from XML
		View view = null ;
		if(convertView == null) view = con.getLayoutInflater().inflate(R.layout.account_list_item, null) ;
		else view = convertView ;
		ImageView headIcon = (ImageView) view.findViewById(R.id.user_headicon) ;
		TextView userName = (TextView) view.findViewById(R.id.user_name) ;
		TextView userId = (TextView) view.findViewById(R.id.user_id) ;
		
		LoginUser user = users.get(position) ;

		headIcon.setImageBitmap(ImageUtil.byteToBitmap(user.profile_image)) ;
		userName.setText(user.name) ;
		userId.setText(user.id) ;
		
		return view;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return users.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return users.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

}
